package com.tools.sqlmaker.make.impl;

import com.tools.sqlmaker.entry.OrgInfo;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: zhoubin
 * @date: 2023/9/7
 */
public class CommLinkConfMaker extends GatewayBaseMaker {

    public CommLinkConfMaker(OrgInfo info) {
        super(info);
    }

    @Override
    public List<Map<String, Object>> getParamList() {
        OrgInfo info = getOrgInfo();
        List<String> sysQmCodeList = getSysQmCodeList();
        List<Map<String, Object>> paramList = new ArrayList<>();

        for (String sysQmCode : sysQmCodeList) {
            char qmCodeNum = sysQmCode.charAt(sysQmCode.length() - 1);
            for (int i = 0; i < info.getMgrNum(); i++) {
                char qmNum = (char) (65 + i);
                Map<String, Object> map = makeDefaultMap();
                map.put("local_qm_code", sysQmCode);
                map.put("rmt_biz_q_code", "MSG_" + getQmCodePre() + qmNum + "_" + qmCodeNum);

                if (info.isDtt()) {
                    map.put("rmt_dtt_q_code", "DTT_" + getQmCodePre() + qmNum + "_" + qmCodeNum);
                    map.put("resp_rmt_dtt_q_name", "DTT_TO_CCGW" + qmCodeNum);
                    map.put("is_dtt", "0");
                    map.put("dtt_frequency", 60);
                }

                paramList.add(map);
            }
        }

        return paramList;
    }

    @Override
    protected Map<String, Object> makeDefaultMap() {
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("id", idMake());
        map.put("dc_code", getOrgInfo().getDcCode());
        map.put("unit_code", getUnitCode());
        map.put("comm_type", "mq");
        map.put("local_qm_code", null);
        map.put("rmt_biz_q_code", null);
        map.put("rmt_dtt_q_code", null);
        map.put("resp_rmt_dtt_q_name", null);
        map.put("ext_param", null);
        map.put("status", "0");
        map.put("is_dtt", "1");
        map.put("dtt_frequency", 0);

        return map;
    }

    @Override
    protected String getTableName() {
        return "t_ccgw_comm_link_conf";
    }
}
